/*
 *
 *  * | Licensed 未经许可不能去掉「OPENIITA」相关版权
 *  * +----------------------------------------------------------------------
 *  * | Author: xw2sy@163.com
 *  * +----------------------------------------------------------------------
 *
 *  Copyright [2024] [OPENIITA]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * /
 */

package cc.iotkit.manager.service.impl;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.manager.IDevicePartsData;
import cc.iotkit.manager.dto.bo.device.DevicePartsBo;
import cc.iotkit.manager.dto.vo.deviceparts.DevicePartsVo;
import cc.iotkit.model.device.DeviceParts;
import cc.iotkit.manager.service.IDevicePartsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * 租户Service业务层处理
 *
 * @author Michelle.Chung
 */
@RequiredArgsConstructor
@Service
public class DevicePartsServiceImpl implements IDevicePartsService {

    private final IDevicePartsData sysDevicePartsData;

    public DevicePartsVo queryById(Long id) {
        return MapstructUtils.convert(sysDevicePartsData.findById(id),DevicePartsVo.class);
    }

    /**
     * 新增保存角色信息
     *
     * @param bo 角色信息
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(DevicePartsBo bo) {
        sysDevicePartsData.save(bo.to(DeviceParts.class));
        return true;
    }

    @Override
    public boolean deleteById(Long id) {
        sysDevicePartsData.deleteById(id);
        return true;
    }

    @Transactional
    public boolean deleteByIds(Collection<Long> ids) {
        sysDevicePartsData.deleteByIds(ids);
        return true;
    }



    @Override
    public Paging<DevicePartsVo> queryPageList(PageRequest<DevicePartsBo> request) {
        Paging<DeviceParts> pages=sysDevicePartsData.findAllByConditions(request.to(DeviceParts.class));
        return pages.to(DevicePartsVo.class);
    }

    @Override
    public List<DevicePartsVo> queryList(DevicePartsBo bo) {
        List<DeviceParts> list=sysDevicePartsData.findAllByCondition(bo.to(DeviceParts.class));
        return MapstructUtils.copyListToList(list,DevicePartsVo.class);
    }



}
